/**
 * @Author: WangHongTao
 * @CreateTime: 2006
 * @Description: CRUD
 * @Copyright: Union Operation Support System.
 */
package org.uoss.applications.framework.dao.jpa.generic;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.uoss.applications.framework.dao.model.QueryModel;
import org.uoss.applications.framework.dao.model.ResultSetModel;
import org.uoss.applications.framework.dao.nativeSQL.NativeSQLDAO;
import org.uoss.core.exception.UOSSException;

public interface GenericDAO<T> extends NativeSQLDAO<T> {
	
	/**
	 * Using HQL to query entities.
	 * 
	 * @param <T>
	 * @param o
	 * @param defaultOrder
	 * @return
	 * @throws UOSSException
	 */
	Collection<T> searchByHQL(String hql, Integer beginIndex,Integer batchSize) throws UOSSException;
	
	/**
	 * Using HQL with query condition to query entities.
	 * 
	 * @param hql
	 * @param parameters
	 * @return
	 */
	Collection<T> searchByHQL(String hql, List<Object> parameters) throws UOSSException;
	
	/**
	 * Using HQL with query condition to query entity result set.
	 * 
	 * @param hql
	 * @param queryModel
	 * @return
	 */
	ResultSetModel<T> searchByHQL(String hql,QueryModel queryModel) throws UOSSException;
	
	/**
	 * Getting the total count of specified entity.
	 * 
	 * @param <T>
	 * @param entityClass
	 * @return
	 * @throws UOSSException
	 */
	int searchTotalCount(Class<T> entityClass) throws UOSSException;

	/**
	 * Getting the total count of specified entity by HQL. 
	 * 
	 * @param hql
	 * @return
	 * @throws UOSSException
	 */
	int searchTotalCountByHQL(String hql) throws UOSSException;
	
	/**
	 * Getting the total count of specified entity by HQL with parameters.
	 * 
	 * @param hql
	 * @param parameters
	 * @return
	 * @throws UOSSException
	 */
	int searchTotalCountByHQL(String hql,Object[] parameters) throws UOSSException;
	
	/**
	 * Getting entity by primary key.
	 * 
	 * @param o
	 * @param id
	 * @return
	 */
	T findByPK(Class<T> entityClass, Serializable id) throws UOSSException;

	/**
	 * Loading entity.
	 * 
	 * @param <T>
	 * @param entityClass
	 * @return
	 * @throws UOSSException
	 */
	Collection<T> load(Class<T> entityClass) throws UOSSException;
	/**
	 * Persist entity.
	 * 
	 * @param o
	 */
	void persist(T entity) throws UOSSException;

	/**
	 * Update entity.
	 * 
	 * @param o
	 * @throws UOSSException
	 */
	void update(T entity) throws UOSSException;

	/**
	 * Delete entity.
	 * 
	 * @param o
	 */
	void delete(T entity) throws UOSSException;
}
